<?php
namespace app\listener\admin;


use Swoole\Server;
use think\facade\Log;

class SaveSwooleListener
{
    protected $server;
    public function __construct(Server $server)
    {
        $this->server = $server;
    }
    public function handle($server)
    {
        Log::write("来了".$this->server->worker_id);
        global $globalSwooleServer;
        $globalSwooleServer = $server;

        // 或者使用容器 app() 设置
        app()->instance('swoole.server', $server);

        echo "Swoole server started and registered globally.\n";
    }
}
